package com.woniu.controller;

import com.woniu.entity.PageData;
import com.woniu.entity.Result;
import com.woniu.entity.dto.CommentDTO;
import com.woniu.entity.dto.LikeDTO;
import com.woniu.pojo.Comment;
import com.woniu.pojo.Like;
import com.woniu.pojo.TrainingInfo;
import com.woniu.service.ICommentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaosong
 * @since 2023-04-01
 */
@RestController
@RequestMapping("/comment")
public class CommentController extends BaseController{

    @Autowired
    private ICommentService commentService;



    //      分页查评论信息。
    @PostMapping("/Search/{currentPage}/{pageSize}")
    @ApiOperation("分页条件查询")
    public Result selectPageAll(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody CommentDTO commentDTO
    ){
        PageData pageData = commentService.search(currentPage,pageSize,commentDTO);
        return toDataResult(pageData);
    }

    //    按照id查询
    @GetMapping("/selectByid/{id}")
    @ApiOperation("ID查询评论表表")
    public Result  selectById(@PathVariable Integer id){

       Comment comment = commentService.selectById(id);
        return toDataResult(comment);
    }

    //    批量删除
    @PostMapping("/delete")
    @ApiOperation("批量删除")
    public  Result deletes(@RequestBody List<String> list){

        boolean b =commentService.removeBatchByIds(list);

        return toResult(b);
    }

    //    新增
    @PostMapping("/save")
    @ApiOperation("新增")
    public Result save(@RequestBody Comment comment){
        boolean flag = commentService.add(comment);
        return toDataResult(flag);
    }
//    修改
    @PostMapping("/update")
    @ApiOperation("修改")
    public Result update(@RequestBody Comment comment){
        Integer num  = commentService.updateComment(comment);
        return toDataResult(num);
    }
}
